if condition ! falsy value


Posted by mijouhsieh on 2023-03-27

// 錯誤寫法
if(!movies || !(movies.length === 0 )) { return }

正確寫法
if(!movies || !movies.length) return

movies.length若為0 就是 false
!false 就是 true
所以不用寫(movies.length === 0)

return 在同一行,不用寫{}


#|| #OR operator #! #debug







Related Posts

Vite系列#安裝外部套件 - Vue Axios

Vite系列#安裝外部套件 - Vue Axios

曼陀號領航計畫(2) Climb the ladder like Spider-Man

曼陀號領航計畫(2) Climb the ladder like Spider-Man

【瀏覽器資料存取】IndexedDB

【瀏覽器資料存取】IndexedDB


Comments